<template>
  <div class="swiper-container" id="floor1Swiper">
    <div class="swiper-wrapper">
      <div class="swiper-slide" v-for="(carousel, index) in lists" :key="index">
        <img :src="carousel.imgUrl" />
      </div>
    </div>
    <!-- 如果需要分页器 -->
    <div class="swiper-pagination"></div>

    <!-- 如果需要导航按钮 -->
    <div class="swiper-button-prev"></div>
    <div class="swiper-button-next"></div>
  </div>
</template>

<script>
//引入swiper
import Swiper from "swiper";

export default {
  name: "Carousel",
  props: ["lists"],
  watch: {
    //解决方案二：watch+nextTick
    lists: {
      immediate:true,
      //通过watch监听bannerList属性的属性值的变化
      async handler(newValue, oldValue) {
        //nextTick：在下次DOM更新循环结束之后执行延迟回调，在修改数据之后，立即使用这个方法，获取更新后的DOM
        await this.$nextTick(() => {
          var mySwiper = new Swiper(".swiper-container", {
            direction: "horizontal", // 水平切换选项
            loop: true, // 循环模式选项
            autoplay: true, //自动切换
            effect: "cube", //切换效果

            // 如果需要分页器
            pagination: {
              el: ".swiper-pagination",
              clickable: true, //点击分页器进行切换
            },

            // 如果需要前进后退按钮
            navigation: {
              nextEl: ".swiper-button-next",
              prevEl: ".swiper-button-prev",
            },

            // 如果需要滚动条
            scrollbar: {
              el: ".swiper-scrollbar",
            },
          });
        });
      }
    },
  },
};
</script>

<style>
</style>